//
//  GSCommonLoginDataManager.m
//  GSLoginDemo
//
//  Created by guoshikeji_a on 2018/7/30.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "GSCommonLoginDataManager.h"

#import "BCUserShareBindRequest.h"

@implementation GSCommonLoginDataManager

+ (instancetype)sharedData {
    static GSCommonLoginDataManager *sm = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sm = [[[self class] alloc] init];
    });
    return sm;
}

- (GSCommonLoginRegisterModel *)registerModel {
    if (!_registerModel) {
        _registerModel = [GSCommonLoginRegisterModel new];
    }
    return _registerModel;
}
- (GSCommonLoginFindPasswordModel *)findPassModel {
    if (!_findPassModel) {
        _findPassModel = [GSCommonLoginFindPasswordModel new];
    }
    return _findPassModel;
}

- (GSCommonLoginRegisterBindingModel *)bindingModel {
    if (!_bindingModel) {
        _bindingModel = [GSCommonLoginRegisterBindingModel new];
    }
    return _bindingModel;
}






//触发绑定
/**
 如果有邀请码 将其与当前登录用户进行绑定
 */
- (void)userRegisterSuccessBindInvatationCode {
    if (self.invatationCode.length) {
        [self requestBindInvatationCodeToUser:self.invatationCode onceAgain:true];
    }
}
//请求绑定
- (void)requestBindInvatationCodeToUser:(NSString *)code onceAgain:(BOOL)again {
    if ([BCUserManager sharedUser].isLogin) {
        BCUserShareBindRequest *request = [BCUserShareBindRequest new];
        request.share_code = code;
        //
        WEAK_SELF
        [request didRequestSuccessed:^(id result, id page) {
            wself.invatationCode = nil;
        }];
        [request didRequestFailed:^(NSError *error) {
            if (again) {
                [wself requestBindInvatationCodeToUser:code onceAgain:false];
            }
        }];
        [request requestServer];
    }
}


@end
